import Base from "./base"

class BrowserHistroy extends Base{
  constructor(router) {
    super(router)
  }

  getCurrentLocation() {
    return window.location.pathname
  }

  updateLocation(location) {
    // window.location.pathname = location        会刷新页面
    history.pushState({}, null, location)
  }

  setupListener() {
    // 监听浏览器前进后退
    window.addEventListener('popstate', () => {
      // 监听回退前进，重新更新
      this.transitionTo(this.getCurrentLocation())
    })
  }
}

export default BrowserHistroy